#pragma once
#include "game.h"
#include "QuadTree.h"
#include <vector>
#include "Mario.h"
#include "Gomba.h"
#include "Turtle.h"
#include "Bullet.h"
#include "FoodBox.h"
#include "FoodMushroom.h"
#include "Sight.h"
#include "Info.h"
#include "CMarioSound.h"

typedef struct Teleport
{
	int sourceX;
	int sourceY;
	int desX;
	int desY;
	int newRoom;
	int screenX;
	int screenY;
};

class CMarioGame :
	public Game
{
protected:
	shared_ptr<CMario> mario;
	shared_ptr<QuadTree> tree;

	CScreen* view;
	CInfo _info;
	RECT _tRect;

	int _gameStatus;

	std::list<shared_ptr<MObject>> _MObjectList;
	std::list<shared_ptr<MObject>> _staticObjectList;
	std::list<shared_ptr<MObject>> _marioCollidedList;
	std::list<shared_ptr<MObject>> _animateList;
	std::list<shared_ptr<MObject>> _pipeList;
	std::list<shared_ptr<Sight>> _sightList;
	std::list<Vector> _checkPointList;
	std::list<Vector> _hitBox;

	std::list<Teleport> _teleList;

	int _delayShootTime;
	bool _allowShoot;

	int _tScore;

	char* _testMap;
	char* _nextMap;

	int _count;

	RECT objRect;
	bool isFalling;

	RECT _finishRect;

	float _winBarY;
	float _winBarX;

	int _sign;

	shared_ptr<Sprite> _bar;

	float _cpX, _cpY;

	bool _startMap;

	bool _mapLoaded;

	bool _isContinue;

public:
	CMarioGame(HINSTANCE hInstance, LPCSTR GameName, LPSTR lpCmdLine, int nShowCmd, int FPS, int ScreenWidth, int ScreenHeight);
	~CMarioGame(void);

	void GameUpdate();
	void RenderFrame();

	void LoadResource();
	void OnKeyDown(int KeyCode);
	void OnKeyUp(int KeyCode);
	inline void LoadMap(char* mapfile);

	void NewMap(char* mapfile, char* infoFile);
	void SaveGame(char* filename, char* infoFile);

	void setStatus(int Status);

	inline void ProcessMenu(int Action);

public:
	static const int STATUS_PLAYING = 1;
	static const int STATUS_MENU = 2;

};

